﻿using UnityEngine;
using System.Collections;

public class Shipmovement : MonoBehaviour {
	
	public Vector2 mousePos;
	
	public int offset = 10;
	public string rotacao;
	public string atual;
	//public float force = 1;
	
	void Start () 
	{
		mousePos.x -= Screen.width/2;
		mousePos.y -= Screen.height/2;
		Screen.showCursor = false;
	}
	
	void FixedUpdate () 
	{
		MousePositionChecker();
		VelocityUpdate();
	}
	
	void RotationUpdate()
	{
		
	}
	
	void MousePositionChecker()
	{
		mousePos = Input.mousePosition;
		mousePos.x -= Screen.width/2;
		mousePos.y -= Screen.height/2;
		
		
		if (mousePos.x > Screen.width/2 + offset)
		{
			transform.Rotate(new Vector3(0,0, ((mousePos.x - Screen.width/2)/130)*-1));
			rotacao = "rotacao = " + ((mousePos.x - Screen.width/2)/100)*-1;
			atual = "Direita";
		}
		else if (mousePos.x < Screen.width/2 - offset)
		{
			transform.Rotate(new Vector3(0,0,((mousePos.x - Screen.width/2)/130)*-1));
			rotacao = "rotacao = " + ((mousePos.x - Screen.width/2)/100);
			atual = "Esquerda";
		}
		
		if (mousePos.y > Screen.height/2 + offset)
		{
			transform.Rotate(new Vector3((((mousePos.y - Screen.height/2)/130)*-1) ,0,0));
			rotacao = "rotacao = " + ((mousePos.y - Screen.height/2)/100)*-1;
			atual = "Cima";
		}
		else if (mousePos.y < Screen.height/2 - offset)
		{
			transform.Rotate(new Vector3((((mousePos.y - Screen.height/2)/130)*-1),0,0));
			rotacao = "rotacao = " + ((mousePos.y - Screen.height/2)/100);
			atual = "Baixo";
		}
	}
	
	
	void VelocityUpdate ()
	{
		if (Input.GetKeyDown(KeyCode.Space))
			rigidbody.velocity = new Vector3(0, 0, 0);
		
		if (Input.GetKey(KeyCode.A))
		{
			rigidbody.AddRelativeForce(Vector3.forward * 100);
		}
		if (Input.GetKey(KeyCode.S))
		{
			rigidbody.AddRelativeForce( -(Vector3.forward * 100));
		}
	}
}